package cc.linker.steplink.crm.merchanth5.service.impl;

import cc.linker.steplink.crm.commons.model.PcUserInfo;
import cc.linker.steplink.crm.merchanth5.commons.UserInfoUtil;
import cc.linker.steplink.crm.merchanth5.dao.acs.DynamicDao;
import cc.linker.steplink.crm.merchanth5.service.acs.DynamicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Service
public class DynamicServiceImpl implements DynamicService {

    @Autowired
    private DynamicDao dynamicDao;
    @Autowired
    private UserInfoUtil userInfoUtil;

    /**
     * 1-新增商品,2-删除商品,3-发布文章,4-下架文章,5-新增标签,6-删除标签,7-新增分群,8-删除分群,
     * 9-开启机器人,10-关闭机器人,11-创建推送,12-关闭推送,13-订单发货,14-调整会员等级,15-调整积分活动
     */
    @Override
    public void recording(String adminId, String orgId, int type, String desc) {
        Map<String, Object> map = new HashMap<>();
        map.put("adminId", adminId);
        map.put("orgId", orgId);
        map.put("type", type);
        map.put("desc", desc);
        this.recording(map);
    }

    @Override
    public void recording(Map<String, Object> map) {
        if (StringUtils.isEmpty(map.get("adminId")) || StringUtils.isEmpty(map.get("orgId"))) {
            return;
        }
        dynamicDao.recording(map);
    }

    @Override
    public void recording(HttpServletRequest request, int type, String desc) {
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        String adminId = userinfo.getAdminId();
        String orgId = userinfo.getOrgId();
        this.recording(adminId, orgId, type, desc);
    }
}
